<?php
$name    = ($role && ($name = $role->getName("name"))) ? $name : $params["name"];
$access_list= ($role && ($access_list = $role->getField("access_list"))) ? $access_list: $params["access_ids"];
?>
<?php $this->render("Admin.Header");?>
<div id="wrapper">
	<div id="leftcol">
    <?php $this->render("Admin.Menu");?>
	</div>
	<div id="rightcol">
		<div id="main">
            <?php $this->render("Admin.Location");?>
			<div>
                <span><?php echo $error_message?></span>
            </div>
			<div class="container-block">
				<form method="POST">
					<table>
					<tbody>
						<tr>
							<td><label class="text-tip">请输入名称：</label></td>
							<td><input type="text" class="text" name="name"
                            value="<?php echo $name?>" /></td>
							<td><span class="error-tip"></span></td>
						</tr>
						<tr>
							<td><label>请选择权限</label></td>
							<td>
                                <?php
                                foreach ($accesses as $k => $v)
                                {
                                ?>
                                    <input type="checkbox" name="access_ids[]" value="<?php echo $k?>" /><?php echo $v["name"]?>
                                    <?php
                                    if (isset($v["child"]) && $v["child"])
                                    {
                                        foreach ($v["child"] as $child)
                                        {
                                    ?>
                                            <input type="checkbox" name="access_ids[]" value="<?php echo $child["id"]?>" /><?php echo $child["name"]?>
                                <?php
                                        }
                                    }
                                    echo "<br />";
                                }
                                ?>
                            </td>
							<td><span class="error-tip"></span></td>
						</tr>
                        <tr><td colspan="2"><input type="submit" value="submit" /></td></tr>
					</tbody>
					</table>
                    <input type="hidden" name="act" value="act" />
				</form>
			</div>
	    </div>
	</div>
</div>
<?php $this->render("Admin.Footer");?>
<script>
(function($){
$(document).ready(function(){
    //set default value for form
    var params = <?php echo json_encode($params)?>;
    var checkboxes = $("input[type=checkbox]");
    var access_list = <?php echo json_encode($access_list)?>;
    var value;
    for (var i = 0; i < access_list.length; i++)
    {
        value = access_list[i]; 
        checkboxes.each(function(i){     
            if ($(this).val() == value)
            {
                $(this).attr("checked", "checked");
            }
        });
    }
});
})(jQuery)
</script>
